<template>
  <div class="icons">
    <swiper :options="swiperOption">
      <swiper-slide v-for="(page,index) of pages" :key="index">
        <div class="icon" v-for="item of page" :key="item.id">
          <div class="icon-img">
            <img class="icon-img-content" :src="item.imgUrl">
            <p class="icon-desc">{{item.desc}}</p>
          </div>
        </div>
      </swiper-slide>
    </swiper>
  </div>
</template>
<script>
export default {
  name: "HomeIons",
  props: {
    list: Array
  },
  data() {
    return {
      swiperOption: {
        pagination: ".swiper-pagination",
        auotplay: false
      },
      iconList: [
        {
          id: "0001",
          desc: "景点门票",
          imgUrl:
            "http://img1.qunarzz.com/piao/fusion/1803/95/f3dd6c383aeb3b02.png"
        },
        {
          id: "0002",
          desc: "游乐场",
          imgUrl:
            "http://img1.qunarzz.com/piao/fusion/1803/95/8246f27355943202.png"
        },
        {
          id: "0003",
          desc: "长沙必游",
          imgUrl:
            "http://img1.qunarzz.com/piao/fusion/1804/ff/fdf170ee89594b02.png"
        },
        {
          id: "0004",
          desc: "亲子游",
          imgUrl:
            "http://img1.qunarzz.com/piao/fusion/1803/50/26ffa31b56646402.png"
        },
        {
          id: "0005",
          desc: "一日游",
          imgUrl:
            "http://img1.qunarzz.com/piao/fusion/1804/5a/13ceb38dcf262f02.png"
        },
        {
          id: "0006",
          desc: "动植物园",
          imgUrl:
            "http://img1.qunarzz.com/piao/fusion/1803/76/eb88861d78fb9902.png"
        },
        {
          id: "0007",
          desc: "主题乐园",
          imgUrl:
            "http://img1.qunarzz.com/piao/fusion/1803/47/c2b659e048b11602.png"
        },
        {
          id: "0008",
          desc: "湘西凤凰",
          imgUrl:
            "http://img1.qunarzz.com/piao/fusion/1803/b8/c5dcdb58deec2402.png"
        },
        {
          id: "0009",
          desc: "年终大促",
          imgUrl:
            "http://img1.qunarzz.com/piao/fusion/1811/f6/e54fad3ea337b02.gif"
        },
        {
          id: "0010",
          desc: "泡温泉",
          imgUrl:
            "http://img1.qunarzz.com/piao/fusion/1803/ab/6f7d6e44963c9302.png"
        }
      ]
    };
  },
  computed: {
    pages() {
      const pagearr = [];
      this.list.forEach((item, index) => {
        const page = Math.floor(index / 8);
        if (!pagearr[page]) {
          pagearr[page] = [];
        }
        pagearr[page].push(item);
      });
      return pagearr;
    }
  }
};
</script>
<style lang="stylus" scoped>
@import '~styles/varibles.styl';

.icons >>>swiper-container {
  padding-bottom: 50%;
}

.icons {
  margin-top: 0.1rem;
  text-align: center;

  .icon {
    width: 25%;
    padding-bottom: 25%;
    float: left;
    position: relative;
    overflow: hidden;

    .icon-img {
      position: absolute;
      left: 0;
      right: 0;
      top: 0;
      bottom: 0.44rem;

      .icon-img-content {
        height: 100%;
        display: block;
        margin: 0 auto;
      }

      .icon-desc {
        color: $darkTextColor;
      }
    }
  }
}
</style>